<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='main'){
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询进入该页面的客户所有订单
	$pids = pdo_getall('jy_quanhuo_item',array('mid'=>$_SESSION['uid']),array('id'),'id');
	$pids=array_keys($pids);
	$params=array('pid'=>$pids,'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status']) && intval($_RQ['status'])<10){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}elseif($_RQ['status']=='10'){
		$return['status']=10;
	}else{
		$return['status']=1;
		$params['status']=1;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 8;
	$list=pdo_getslice('jy_quanhuo_item_jieli',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
			foreach($list as &$item){
				$user=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']));
				$info=pdo_get('jy_quanhuo_item',array('id'=>$item['pid'],'uniacid'=>$_SESSION['uniacid']));
				$item['user']=$user;
				$item['info']=$info;
				$item['formdata']=pdo_getcolumn('jy_quanhuo_item_formdata',array('pid'=>$item['pid'],'orderid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'data');
				$item['formdata']=json_decode($item['formdata'],true);
				$item['typestatus']=$item['status']==0?'待支付':'已完成';
				$item['typetitle']=$this->itemtypes()[$info['type']];
				$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			}
	}
	$return['list']=$list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_quanhuo_feelog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['mid']));
	//项目信息
	$item=pdo_get('jy_quanhuo_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['pid']));	
	//自定义字段数据
	$order['groupsendsettitle']=$item['groupsendset']==1?'快递发货':$item['groupsendset']==0?'无需物流':'自提点提货';
	$formdata=pdo_get('jy_quanhuo_item_formdata',array('mid'=>$order['mid'],'pid'=>$order['pid'],'uniacid'=>$_SESSION['uniacid']));
	$order['data']=json_decode($formdata['data'],true);
	$order['diydata']=json_decode($formdata['diydata'],true);
	foreach($formdata['fileds'] as $k=>&$fv){
				if($order['type']!=1 && $fv['total']<1){
					unset($formdata['fileds'][$k]);
				}else{
					foreach($fv as $fk=>&$f){
						if($f['type']==1){
							$fv['title'] =$f['data'];
						}
						if($f['type']==18){
							$fv['fee'] =$f['data']*$fv['total'];
						}
						if($f['type']==3){
							$fv['image'] =$f['data'];
						}
					}
				}
	}
	$formdata['data']=json_decode($formdata['data'],true);
	foreach($formdata['data'] as $v){
		if($v['type']==7){
			$order['address']=$v['data']['province'].''.$v['data']['city'].''.$v['data']['district'].''.$v['data']['xiangxi'];
		}
		if($v['type']==8){
			$order['mobile']=$v['data'];
		}
		if($v['title']=='联系人'){
			$order['name']=$v['data'];
		}
	}
	$return['formdata']=$formdata;
	if($item['status']==0){
		$item['typestatus']='待支付';
	}
	if($item['status']==1){
		$item['typestatus']='已支付';
	}
	if($item['status']==2){
		$item['typestatus']='已发货';
	}
	if($order['status']>=3){
		$order['typestatus']=$order['status']==3?'已取消':'已完成';
	}
	if($order['status']>=2){
				$order['express']=pdo_get('jy_quanhuo_order_express',array('order_id'=>$order['id'],'uniacid'=>$_SESSION['uniacid']));
				$order['express']['express_name']=$return['express'][$order['express']['express_id']-1]['name'];
	}
	$order['typetitle']=$this->itemtypes()[$order['type']];
	$order['createtime']=date('Y-m-d H:i:s', $order['createtime']);
	$order['sendtime']=date('Y-m-d H:i:s', $order['sendtime']);
	$order['paytime']=date('Y-m-d H:i:s', $order['paytime']);
	$return['order']=$order;
	$return['member']=$member;
	$return['item']=$item;
	$return['fileds']=$fileds;
	exi($return);
}